package adv8.server1;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatClient {
    public static void main(String[] args) {
        //聊天客户端 127.0.0.1
        Socket s = null;
        try {
            s = new Socket("localhost", 8888);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            Scanner input = new Scanner(System.in);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out);
            while (true) {
                System.out.print("唠嗑：");
                String msg = input.next();
                pw.println(msg);//发送到服务器
                pw.flush();
                String reply = br.readLine();
                System.out.println("服务器说：" + reply);
                if ("byebye".equals(msg)) {
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
